package com.fante.dubbo.manage.exception;

import org.apache.shiro.web.util.WebUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局统一的异常处理
 * @Date 2020/6/6
 */
@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(org.apache.shiro.authz.AuthorizationException.class)
    public String handleException(RedirectAttributes redirectAttributes, Exception exception, HttpServletRequest httpServletRequest) {
        redirectAttributes.addFlashAttribute("message", " 你没有权限执行这个操作");
        String requestUri = WebUtils.getRequestUri(httpServletRequest);
        return "redirect:/" + requestUri.split("/")[1];
    }
}
